<template>
	<el-form ref="basicInfoFormRef" :model="info" :rules="rules" label-width="150px" style="min-height: 400px;">
		<el-row>
			<el-col :span="12">
				<el-form-item label="表名称" prop="tableName">
					<el-input placeholder="请输入仓库名称" v-model="info.tableName" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="表描述" prop="tableComment">
					<el-input placeholder="请输入" v-model="info.tableComment" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="作者" prop="author">
					<el-input placeholder="请输入" v-model="info.author" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="备注" prop="remark">
					<el-input type="textarea" :rows="3" v-model="info.remark"></el-input>
				</el-form-item>
			</el-col>

			<el-col :span="12">
				<el-form-item label="实体类名称" prop="className">
					<el-input placeholder="请输入" v-model="info.className" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item prop="packageName">
					<span slot="label">
						生成包路径
						<el-tooltip content="生成在哪个java包下，例如 com.ruoyi.system" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<el-input v-model="info.packageName" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item prop="classRemark">
					<span slot="label">
						实体类描述
						<el-tooltip content="用作类描述，例如 用户" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<el-input v-model="info.classRemark" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item prop="jiekouPath">
					<span slot="label">
						接口路径
						<el-tooltip content="接口名:api/app/user,api/app/user/info" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<el-input v-model="info.jiekouPath" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item prop="genType">
					<span slot="label">
						生成代码方式
						<el-tooltip content="默认为zip压缩包下载，也可以自定义生成路径" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<el-radio v-model="info.genType" label="0">zip压缩包</el-radio>
					<el-radio v-model="info.genType" label="1">自定义路径</el-radio>
				</el-form-item>
			</el-col>

			<el-col :span="12" v-if="info.genType == '1'">
				<el-form-item prop="genPath">
					<span slot="label">
						自定义路径
						<el-tooltip content="填写磁盘绝对路径，若不填写，则生成到当前Web项目下" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<el-input v-model="info.genPath">
						<el-dropdown slot="append">
							<el-button type="primary">
								最近路径快速选择
								<i class="el-icon-arrow-down el-icon--right"></i>
							</el-button>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item @click.native="info.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item>
					<span slot="label">
						上级菜单
						<el-tooltip content="分配到指定菜单下，例如 系统管理" placement="top">
							<i class="el-icon-question"></i>
						</el-tooltip>
					</span>
					<TreeSelect v-model="info.parentMenuId" :treeData="menus" :show-count="true" placeholder="请选择系统菜单"
						:defaultProps="{id:'id',label:'name',children:'children'}" />
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";
	export default {
		props: {
			info: {
				type: Object,
				default: null,
			},
			menus: {
				type: Array,
				default: []
			},
		},
		data() {
			return {
				rules: {
					tableName: [{
						required: true,
						message: "请输入表名称",
						trigger: "blur"
					}],
					tableComment: [{
						required: true,
						message: "请输入表描述",
						trigger: "blur"
					}],
					className: [{
						required: true,
						message: "请输入实体类名称",
						trigger: "blur"
					}],
					author: [{
						required: true,
						message: "请输入作者",
						trigger: "blur"
					}],
					packageName: [{
						required: true,
						message: "请输入生成包路径",
						trigger: "blur"
					}],
					jiekouPath: [{
						required: true,
						message: "请输入接口名",
						trigger: "blur"
					}],
					classRemark: [{
						required: true,
						message: "请输入功能名",
						trigger: "blur"
					}],
				}
			};
		},
		mounted() {
		},
		methods: {
			checkForm(event) {
				this.$refs.basicInfoFormRef.validate(res => {
					event(res)
				});
			},
			/** 转换菜单数据结构 */
			normalizer(node) {
				if (node.children && !node.children.length) {
					delete node.children;
				}
				return {
					id: node.id,
					label: node.name,
					children: node.children
				};
			},
		}
	};
</script>